package com.ysl.fairy_could_class.controller;

import com.ysl.fairy_could_class.domain.Teacher;
import com.ysl.fairy_could_class.service.TeacherService;
import com.ysl.fairy_could_class.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/teacher")
@Api(tags = "教师管理")
public class TeacherController {
    @Autowired
    TeacherService service;
    @GetMapping("/getUserListAll")
    @ApiOperation(value = "获取教师列表")
    public AjaxResult getTeacherListAll() {
        System.out.println(service.selectAll());
        return AjaxResult.success(service.selectAll());
    };
    @GetMapping("/getTeacherById")
    @ApiOperation(value = "根据id查询教师信息")
    public AjaxResult getTeacherById(int id) {
        System.out.println(service.selectById(id));
        return AjaxResult.success(service.selectById(id));
    }
    @PostMapping("/addTeacher")
    @ApiOperation(value = "新增教师")
    public AjaxResult addTeacher(@RequestBody Teacher teacher) {
        return AjaxResult.success(service.SaveTeacher(teacher));
    }
    @PostMapping("/UpdateTeacher")
    @ApiOperation(value = "修改教师密码")
    public AjaxResult UpdateTeacher(@RequestBody Teacher teacher){
        return AjaxResult.success(service.UpdateTeacher(teacher));
    }
    @PostMapping("/DeleteTeacher")
    @ApiOperation(value = "删除教师")
    public AjaxResult DeleteTeacher(int id) {
        return AjaxResult.success(service.DeleteTeacher(id));
    }
    @PostMapping("/TeacherLogin")
    @ApiOperation(value = "教师登录")
    public AjaxResult TeacherLogin(Teacher teacher) {
        return AjaxResult.success(service.checkTeacher(teacher));
    }
}
